package com.photoeditor.demo.ui.widget.image.edit;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.AdapterView;
import android.widget.FrameLayout;

import com.photoeditor.R;
import com.photoeditor.demo.model.image.frame.IFrameChangeListener;
import com.photoeditor.demo.ui.widget.HorizontalListView;
import com.photoeditor.demo.ui.widget.image.frame.FrameListAdapter;


/**
 * @dest 相框选择列表
 */
public class FrameBarView extends FrameLayout {
    private IFrameChangeListener mListener;

    private HorizontalListView frameList;
    private FrameListAdapter mFrameListAdapter;
//    private Bitmap mBaseBitmap;


    public FrameBarView(Context context) {
        this(context, null);
    }

    public FrameBarView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public FrameBarView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        frameList = (HorizontalListView) this.findViewById(R.id.frame_template_list);
    }

    public void init(IFrameChangeListener listener) {
        mListener = listener;
        mFrameListAdapter = new FrameListAdapter(getContext(), 0);
       /* if(mBaseBitmap!=null){
            mFrameListAdapter.setBaseBitmap(mBaseBitmap);
        }*/
        frameList.setAdapter(mFrameListAdapter);
//        mFrameListAdapter.setInitData();
        frameList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                mFrameListAdapter.setSelectedPosition(position, view);
                if (mListener != null) {
                    mListener.frameChange(mFrameListAdapter.getItem(position));
                }
            }
        });
        setBackgroundResource(R.drawable.image_edit_sencond_bg);
    }

    public void reset() {
        mFrameListAdapter.setSelectedPosition(0);
    }

    public void onDestory(boolean isActfinish) {
        if (mFrameListAdapter != null) {
            mFrameListAdapter.onDestory(isActfinish);
        }
    }
}
